<style type="text/css">
<!--
.textoasigna {
	font-family: Calibri;
	font-size: 11px;
	font-style: italic;
}
-->
</style>

<?php 
include("conexion.php");

$codkardex=$_POST['codkardex'];

$sqlsum=mysql_query("Select * from detalle_actos_kardex where kardex = '$codkardex'", $conn) or die(mysql_error());

while($rowsum = mysql_fetch_array($sqlsum)){
   $itemdiv=$rowsum['item'];
   $sqlnumer=mysql_query("Select * from contratantesxacto where item = '$itemdiv' and parte = '1'", $conn) or die(mysql_error());
    $numeroitem = mysql_num_rows($sqlnumer);
	//echo $numeroitem ;
   $sqlnumer2=mysql_query("Select * from contratantesxacto where item = '$itemdiv' and parte = '2'", $conn) or die(mysql_error());
   $numeroitem2 = mysql_num_rows($sqlnumer2);
   //echo $numeroitem2 ;
   
   
       
	  $resuldivi= (100)/(intval($numeroitem));
	  $sqldivi="UPDATE contratantesxacto set porcentaje='$resuldivi' WHERE item='$itemdiv' and parte = '1'"; 
      mysql_query($sqldivi,$conn) or die(mysql_error());
	  
	  $resuldivi2= (100)/(intval($numeroitem2));
	  $sqldivi2="UPDATE contratantesxacto set porcentaje='$resuldivi2' WHERE item='$itemdiv' and parte = '2'"; 
      mysql_query($sqldivi2,$conn) or die(mysql_error());
	  	
}


$sqlkardex=mysql_query("Select * from detalle_actos_kardex where kardex = '$codkardex'", $conn) or die(mysql_error());

while($rowkardex = mysql_fetch_array($sqlkardex)){
   $item=$rowkardex['item'];
   $sqlitem=mysql_query("Select * from contratantesxacto where item = '$item' ", $conn) or die(mysql_error());
    while($rowitem = mysql_fetch_array($sqlitem)){
	echo "<table width='892' border='1' bgcolor='#FFFFFF' cellpadding='0' cellspacing='0' bordercolor='#CCCCCC'>
            <tr>
              <td width='149'><div style='width:149px; height:auto; border:0px;'><span class='textoasigna'>".$rowkardex['desacto']."</span></div></td>
              <td width='163'><div style='width:163px; height:auto; border:0px;'><span class='textoasigna'>"; 
			  $idcontratante=$rowitem['idcontratante'];
			  $sqlcontrante=mysql_query("Select * from cliente2 where idcontratante = '$idcontratante'", $conn) or die(mysql_error());
			  $rowcontra=mysql_fetch_array($sqlcontrante);
			  if($rowcontra['tipper']=="N") { 
			  
			  
			  $nomyape=strtoupper($rowcontra['apepat']." ".$rowcontra['apemat'].", ".$rowcontra['prinom']." ".$rowcontra['segnom']);
	$textorefe=str_replace("?","'",$nomyape);
	$textoampers=str_replace("*","&",$textorefe);
	$textoamperss=str_replace("ñ","Ñ",$textoampers);
	echo strtoupper($textoamperss);    
			  }else { 
			
			   $empresita=strtoupper($rowcontra['razonsocial']);
	         $textorefe=str_replace("?","'",$empresita);
						  $textoampers=str_replace("*","&",$textorefe);
						  $textoamperss=str_replace("ñ","Ñ",$textoampers);
						  echo strtoupper($textoamperss);
			  
			  }
			  echo"</span></div></td>
              <td width='170'><div style='width:170px; height:auto; border:0px;'><span class='textoasigna'>";
			  $conditiion=$rowitem['idcondicion'];
			  $consucondi=mysql_query("Select * from actocondicion where idcondicion = '$conditiion' ", $conn) or die(mysql_error());
			  $rowconddi=mysql_fetch_array($consucondi);
			  echo strtoupper($rowconddi['condicion']);
			   echo"</span></div></td>
              <td width='80'>
				<div style='width:80px; height:auto; border:0px;'>"; if($rowitem['uif']!="A"  and $rowitem['uif']!="R" ){echo"<input name='".$rowitem['item']."' title='".$rowitem['id']."' id='".$rowitem['idcondicion']."' type='text' size='5' onchange='recal(this.name,this.id,this.value,this.title)' value='".$rowitem['porcentaje']."' />";} echo"</div>
             </td>
              <td width='30'><div style='width:30px; height:auto; border:0px;'><span class='textoasigna'>".strtoupper($rowitem['uif'])."</span></div></td>
              <td width='55'><div style='width:55px; height:auto; border:0px;'>"; if ($rowitem['formulario']=="1"){
			  echo "<a href='#' onClick='validarformular(".$rowitem['idcontratante'].")'><img src='iconos/formu.png' width='34' height='29' border='0' /></a>";
			  
			  } echo"</div></td>
			  <td width='73'><div style='width:73px; height:auto; border:0px;'>"; if($rowitem['montop']=="1"){echo "<input style='text-transform:uppercase;' id='".$rowitem['id']."' name='".$rowitem['idcondicion']."' title='".$rowitem['item']."' type='text' size='5' onchange='remonto(this.name,this.id, this.title, this.value)' value='".$rowitem['monto']."' />";} echo"</div></td>
			 
			  
			  <td width='172'><div style='width:172px; height:auto; border:0px;'>";
			if($rowitem['montop']=="1"){
			  if($rowitem['ofondo']==""){
				     echo" <input id='h".$rowitem['idcontratante']."' style='text-transform:uppercase;' name='r".$rowitem['idcondicion']."' title='".$rowitem['id']."' type='text' size='21' onchange='fondos(this.title,this.value)' value='' />";	 
				} else{		
					echo" <input id='h".$rowitem['idcontratante']."' style='text-transform:uppercase;' name='r".$rowitem['idcondicion']."' title='".$rowitem['id']."' type='text' size='21' onchange='fondos(this.title,this.value)' value='".$rowitem['ofondo']."' />";
					}

			}echo"</div></td>
            </tr>
          </table>"; 
    }

}
?>